import os

import PIL
import cv2
import numpy as np
from PIL import Image
import PIL.ImageOps

ori = r'G:\ml2021\pycharm\OriginalSiamese\my\train'
# 增加样本量，不够8张的反转成8张
countlist = []
n = 8
for folder in os.listdir(ori):
    path = os.path.join(ori, folder)
    files = os.listdir(path)
    print(files)
    count = 0
    for file in files:
        if len(os.listdir(path)) >= n:
            break
        count = len(os.listdir(path))
        fullpath = os.path.join(path, file)
        img1 = Image.open(fullpath)
        img0 = PIL.ImageOps.mirror(img1)
        name = file.split('.')[0]
        savePath = os.path.join(path, name + str(count) + '_i.jpg')
        img0.save(savePath)
        # cv2.imwrite(savePath, img0)

    countlist.append(len(os.listdir(os.path.join(ori, folder))))
print(np.mean(countlist))
